package com.rj.data.sink;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class FileSink implements Sink<List<String>> {
    private String destFile;
    private Integer cache;

    public FileSink(String destFile, Integer cache) {
        this.destFile = destFile;
        this.cache = cache;
    }

    @Override
    public void writeLines(List<String> lines, boolean append, boolean force, String splitter) throws IOException {
        if (force) {
            FileUtils.writeLines(new File(destFile), lines, append);
        } else {
            if (lines.size() >= cache) {
                FileUtils.writeLines(new File(destFile), lines, append);
            }
        }
    }
}
